# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=cl-cffi
_pkgname="${pkgname#cl-}"
pkgver=0.24.1.r23.gac07d76
pkgrel=1
pkgdesc='Common Foreign Function Interface for Common Lisp'
arch=('any')
url='https://cffi.common-lisp.dev/'
license=('MIT')
depends=(
  'common-lisp'
  'cl-asdf'
  'cl-babel'
  'cl-alexandria'
  'cl-trivial-features'
  'cl-ppcre'
  'cl-json'
  'libffi'
)
makedepends=('git')
checkdepends=('sbcl' 'cl-bordeaux-threads' 'cl-rt')
_commit='ac07d762d89ca03688392b4d9a4ca1784b995a99'
source=("$pkgname::git+https://github.com/cffi/cffi#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed -e 's/^v//' -e 's/-/.r/' -e 's/-/./g'
}

prepare() {
  cd "$pkgname"

  # add local dir so asdf can pick up library
  sed \
    -i tests/run-tests.lisp \
    -e '/(require "asdf")/a (push (uiop/os:getcwd) asdf:*central-registry*)'
}

check() {
  cd "$pkgname"

  sbcl --script tests/run-tests.lisp 

  # delete test artifacts
  find . -name '*.o' -delete -or -name '*.so' -delete
}

package() {
  cd "$pkgname"

  # library
  install -vd "$pkgdir/usr/share/common-lisp/source/$_pkgname"
  cp -vr \
    examples grovel libffi src tests toolchain uffi-compat \
    ./*.asd \
    "$pkgdir/usr/share/common-lisp/source/$_pkgname"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" COPYRIGHT
}
